package com.lyh.notes.model.base;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponse <T>{

    private int code;
    private String message;
    private T data;

    public static <T>ApiResponse<T> success(T data) {
        return new ApiResponse<T>(200,"success",data);
    }
    public static <T>ApiResponse<T> success(String message,T data) {
        return new ApiResponse<T>(200,message,data);
    }

    public static ApiResponse<EmptyVO> success(){
        return success(new EmptyVO());
    }

    public static <T> ApiResponse<T> error(int code, String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }
    public static <T>ApiResponse<T> error(int code, String message, T data) {
        return new ApiResponse<T>(code,message,data);
    }

    public static <T>TokenApiResponse<T> success(String message,T data,String token) {
       return new TokenApiResponse<>(HttpStatus.OK.value(), message,data,token);
    }
}
